import { Body, Controller, Post, UploadedFile, UseInterceptors } from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { ApiBody, ApiConsumes, ApiTags } from '@nestjs/swagger';
import { util_ApiResponse_Base } from '@/common/util/apiResponse';
import { FileManage_Service } from './fileManage.service';
import { FileManage_TencentBucketUploadFile_Dto } from './assets/fileManage.dto';
import { util_Index_ReturnContent } from '@/common/util/index';

@Controller('/adm/fileManage')
@ApiTags('fileManage 文件上传')
export class FileManage_Controller {
  constructor(private readonly fileManage_Service: FileManage_Service) {}

  @Post('/tcupload')
  @UseInterceptors(FileInterceptor('file'))
  @ApiConsumes('multipart/form-data')
  @ApiBody({ description: '文件上传' })
  @util_ApiResponse_Base({
    dataType: 'dataType_string',
    status: 201,
    description: '上传成功',
    //apiKey: '/adm/fileManage/tcupload Post',
    type: '文件地址',
    summary: '上传文件',
  })
  async fileManage_TencentBucketUploadFile(
    @UploadedFile() file: any,
    @Body() detail: FileManage_TencentBucketUploadFile_Dto,
  ) {
    return util_Index_ReturnContent(
      await this.fileManage_Service.fileManage_TencentBucketUploadFile({
        ...detail,
        fileName: file.originalname,
        fileContent: file.buffer,
      }),
    );
  }
}
